home *** CD-ROM | disk | FTP | other *** search
/ Sound Fx / Sound Fx.iso / Software / UNZIPED / DWSTK / DWS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-10-13  |  15.1 KB  |  500 lines

  1. (******************************************************************************
  2. File:      dws.pas
  3. Version:     2.22
  4. Tab stops: every 2 columns
  5. Project:   DiamondWare's Sound ToolKit
  6. Copyright: 1994-1995 DiamondWare, Ltd.  All rights reserved.
  7. Written:     Keith Weiner & Erik Lorenzen & Tom Repstad
  8. Purpose:   Creates dws.tpu
  9. History:   94/10/09 KW Started
  10.            94/11/27 EL Finalized for 1.0
  11.            95/03/19 EL Finalized for 1.01, Added new const dws_Busy
  12.            95/04/06 EL Finalized for 1.02, Added new const dws_IRQDISABLED
  13.                      95/04/06 EL Finalized for 1.03, no changes
  14.                      95/07/23 EL Finalized for 1.04, no changes
  15.                      95/07/23 EL Finalized for 2.00, no changes
  16.                      95/10/16 EL Finalized for 2.10, no changes
  17.                      95/08/29 TR Initial conversion to pascal pmode
  18.                      95/10/16 EL Initial cleanup of pmode conversion, Added Wrap
  19.                      95/10/23 EL Changed structs to use dws_ADDRESS (not dws_BTPTR)
  20.                      95/10/25 EL Finalized for 2.20
  21.                      95/12/09 EL Finalized for 2.21
  22.                      96/10/10 EL Finalized for 2.22, no changes
  23.  
  24. NB: The dwt (timer) code is not compatible with source profilers
  25. ******************************************************************************)
  26.  
  27.  
  28. NB: This file is provided as a reference for the programmer, it is not needed
  29.     in order to use the STK.
  30.  
  31.  
  32. unit DWS;
  33.  
  34. interface
  35.  
  36. {$IFDEF DPMI}
  37. uses winapi;
  38. {$ENDIF}
  39.  
  40. const
  41.  
  42. (*****************************************************************************)
  43.  
  44.  
  45.     (*
  46.      . The following is intterrupt range that STKRUN will become
  47.      . resident in.
  48.     *)
  49.     dws_FIRSTINT = $60;
  50.     dws_LASTINT  = $66;
  51. (*---------------------------------------------------------------------------*)
  52.  
  53.  
  54.   (*
  55.    . The following is the complete list of possible values for dws_errno.
  56.    . dws_errno may be set by any dws_ function.  Check its value whenever
  57.    . the return value of a dws_ function is 0 (error).
  58.   *)
  59.     dws_EZERO                                                 =  0;
  60.  
  61.   (* The following 3 errors may be triggered by any dws_ function *)
  62.     dws_NOTINITTED                                        =  1;
  63.     dws_ALREADYINITTED                                =  2;
  64.     dws_NOTSUPPORTED                                    =  3;
  65.  
  66.   (* The following 4 errors may be triggered by dws_DetectHardWare *)
  67.     dws_DetectHardware_UNSTABLESYSTEM =  4;
  68.     dws_DetectHardware_BADBASEPORT        =  5;
  69.     dws_DetectHardware_BADDMA                 =  6;
  70.     dws_DetectHardware_BADIRQ                 =  7;
  71.  
  72.   (* The following error may be triggered by dws_Kill *)
  73.     dws_Kill_CANTUNHOOKISR                        =  8;
  74.  
  75.   (* The following error may be triggered by any dws_X (mixer) function *)
  76.     dws_X_BADINPUT                                        =  9;
  77.  
  78.   (* The following 3 errors may be triggered by any dws_D (dig) function *)
  79.     dws_D_NOTADWD                                         =  10;
  80.     dws_D_NOTSUPPORTEDVER                         =  11;
  81.     dws_D_INTERNALERROR                             =  12;
  82.  
  83.   (* The following error may be triggered by dws_DPlay *)
  84.     dws_DPlay_NOSPACEFORSOUND                 =  13;
  85.  
  86.   (* The following 2 errors may be triggered by dws_DSetRate *)
  87.     dws_DSetRate_FREQTOLOW                        =  14;
  88.     dws_DSetRate_FREQTOHIGH                     =  15;
  89.  
  90.   (* The following 3 errors may be triggered by dws_MPlay *)
  91.     dws_MPlay_NOTADWM                                 =  16;
  92.     dws_MPlay_NOTSUPPORTEDVER                 =  17;
  93.     dws_MPlay_INTERNALERROR                     =  18;
  94.  
  95.   (*
  96.    . The following error may be triggered by any dws_ function
  97.    . (except dws_ErrNo and dws_Init) if called from an Interrupt
  98.    . Service Routine (ISR).  If you're not sure whether this applies
  99.    . to you: it probably doesn't.
  100.   *)
  101.     dws_BUSY                                                    =  19;
  102.  
  103.   (*
  104.    . The following error may be triggered by dws_Init, dws_Kill,
  105.    . and dws_DetectHardware.  It will only occur if interrupts are
  106.    . disabled.  Interrupts must be enabled when calling.  If you're
  107.    . not sure whether this applies to you: it probably doesn't.
  108.   *)
  109.     dws_IRQDISABLED                                     =  20;
  110.  
  111. {$IFDEF DPMI}
  112.     (*
  113.      . The following errors will only come up when using the protected mode
  114.      . extension to the STK
  115.     *)
  116.     dws_NOTRESIDENT                                     = 100;
  117.     dws_NOMEM                                                 = 101;
  118.  
  119. {$ENDIF}
  120.  
  121. (*---------------------------------------------------------------------------*)
  122.  
  123.  
  124.   (*
  125.    . The follwing section defines bitfields which are used by various
  126.    . dws_ functions.  Each bit in a bitfield, by definition, may be
  127.    . set/reset independantly of all other bits.
  128.   *)
  129.  
  130.   (* The following 2 consts indicate the capabilities of the user's hardware *)
  131.   dws_capability_FM                  = $0001;
  132.   dws_capability_DIG                 = $0002;
  133.  
  134.  
  135.   (* The following 2 consts indicate the status of specified digital sounds *)
  136.   dws_DSOUNDSTATUSPLAYING            = $0001;
  137.   dws_DSOUNDSTATUSSEQUENCED          = $0002;
  138.  
  139.  
  140.   (* The following 2 consts indicate the status of music playback *)
  141.   dws_MSONGSTATUSPLAYING             = $0001;
  142.   dws_MSONGSTATUSPAUSED              = $0002;
  143.  
  144.   (*
  145.    . Below are the timer rates supported by DWT.  Anything in between
  146.    . the listed values will cause the DOS/BIOS clock to tick erratically
  147.    . and is thus not allowed.  Any value higher than 145.6 Hz means
  148.    . you have some very special circumstances; DWT won't fit your needs
  149.    . anyway.
  150.   *)
  151.   dwt_18_2HZ                         = 0;            (*18.2 Hz*)
  152.   dwt_36_4HZ                         = 1;            (*36.4 Hz*)
  153.   dwt_72_8HZ                         = 2;            (*72.8 Hz*)
  154.   dwt_145_6HZ                        = 3;            (*145.6 Hz*)
  155. (*****************************************************************************)
  156.  
  157.  
  158.  
  159. type
  160.  
  161.   (*
  162.    . The following section declares the record types used by the STK.  In each
  163.    . case, the user must create an instance of the record prior to making
  164.    . a call to an STK function which takes a pointer to it.  The STK does
  165.    . not keep a pointer to any of these records internally; after the call
  166.    . returns, you may deallocate it, if you wish.
  167.    .
  168.    . NB: The STK _does_ keep pointers to songs and digitized sound buffers!
  169.   *)
  170.  
  171.  
  172.   (*
  173.      . These are types which a built on standard declarations and
  174.      . are used below
  175.     *)
  176.     dws_BTPTR  = ^byte;
  177.   dws_WDPTR  = ^word;
  178.  
  179.     {$IFDEF DPMI}
  180.         dws_ADDRESS = record
  181.             ptr     : pointer;
  182.             rmseg : longint;
  183.         end;
  184.     {$ELSE}
  185.         dws_ADDRESS = ^byte;
  186.     {$ENDIF}
  187.  
  188.  
  189.  
  190.   (*
  191.    . dws_DetectHardWare can be told _not_ to autodetect particular values
  192.    . about the installed hardware.  This is useful if detecting DMA channel,
  193.    . for example, consistently causes a machine lockup.  To override the
  194.    . autodetect for a setting, set the corresponding field in this struct
  195.    . to the correct value.  Otherwise, set the field to ffff hex.  Since
  196.    . the autodetect is reliable, this is the recommended course of action,
  197.    . except in cases of known problems.
  198.   *)
  199.   dws_DETECTOVERRIDES = record
  200.         baseport : word;                                (*base addr of sound card (often 220) hex*)
  201.  
  202.     digdma   : word;                  (*DMA channel*)
  203.     digirq   : word;                  (*IRQ level*)
  204.  
  205.     reserved : array[1..10] of word;
  206.  
  207.   end;
  208.  
  209.  
  210.   (*
  211.    . A pointer to this record is passed to dws_DetectHardWare, which fills
  212.    . it in.  It is then passed unmodified to dws_Init.  If you plan on
  213.    . writing this record out to a file, it's important that you write
  214.    . the entire contents.  There is information (for internal STK use only)
  215.    . in the reserved[] field!
  216.   *)
  217.   dws_DETECTRESULTS = record
  218.     baseport   : word;                (*base addr of sound card (often 220) hex*)
  219.  
  220.     capability : word;                (*see constants, above*)
  221.  
  222.     (* The following 3 fields are only valid if FM music is supported *)
  223.     mustyp     : word;                (*0=none, 1=OPL2*)
  224.     musnchan   : word;                (*1=mono*)
  225.     musnvoice  : word;                (*num hardware voices (11 for FM)*)
  226.  
  227.     (* The following 4 fields are only valid if digitized sound is supported *)
  228.     dignbits   : word;                (*0=none, 8=8 bit*)
  229.     dignchan   : word;                (*1=mono*)
  230.     digdma     : word;                (*DMA channel*)
  231.     digirq     : word;                (*IRQ level*)
  232.  
  233.     mixtyp     : word;                (*1=software, 2+ is hardware*)
  234.  
  235.     reserved   : array[1..44] of byte;(*there are important values in here...*)
  236.  
  237.   end;
  238.  
  239.  
  240.   (*
  241.    . A pointer to this struct is passed as a parameter to dws_Init.  This
  242.    . allows the user to tell the STK to use less than the full capabilities
  243.    . of the installed sound hardware, and/or the user's sound board
  244.    . may not support every feature of the STK.
  245.   *)
  246.   dws_IDEAL = record
  247.     musictyp   : word;         (*0=No Music, 1=OPL2*)
  248.  
  249.     digtyp     : word;         (*0=No Dig, 8=8bit*)
  250.     digrate    : word;         (*sampling rate, in Hz*)
  251.     dignvoices : word;         (*number of voices (up to 16)*)
  252.     dignchan   : word;         (*1=mono*)
  253.  
  254.     reserved   : array[1..6] of byte;
  255.  
  256.   end;
  257.  
  258.  
  259.   (*
  260.    . A pointer to this record is passed to dws_DPlay.
  261.    . Note that the soundnum field is filled in by dws_DPlay as a return value.
  262.   *)
  263.   dws_DPLAYREC = record
  264.         snd          : dws_ADDRESS;      (*pointer to buffer which holds a .DWD file*)
  265.     count    : word;           (*number of times to play, or 0=infinite loop*)
  266.     priority : word;           (*higher numbers mean higher priority*)
  267.     presnd   : word;           (*soundnum to sequence sound _after_*)
  268.     soundnum : word;           (*dws_DPlay returns a snd number from 10-65535*)
  269.  
  270.     reserved : array[1..20] of byte;
  271.  
  272.   end;
  273.  
  274.  
  275.   (* A pointer to this record is passed to dws_MPlay. *)
  276.   dws_MPLAYREC = record
  277.         track : dws_ADDRESS;             (*pointer to buffer which holds a .DWM file*)
  278.     count : word;              (*number of times to play, or 0=infinite loop*)
  279.  
  280.     reserved : array[1..10] of byte;
  281.  
  282.   end;
  283.  
  284.  
  285.   (*
  286.      . These are types which a built on the above declarations
  287.   *)
  288.   dws_DOPTR  = ^dws_DETECTOVERRIDES;
  289.   dws_DRPTR  = ^dws_DETECTRESULTS;
  290.   dws_IDPTR  = ^dws_IDEAL;
  291.   dws_DPPTR  = ^dws_DPLAYREC;
  292.   dws_MPPTR  = ^dws_MPLAYREC;
  293.  
  294. (*****************************************************************************)
  295.  
  296.  
  297. (*
  298.  . This function is callable at any time.  It returns the number of the
  299.  . last error which occured.
  300. *)
  301. function dws_ErrNo : word;
  302. (*---------------------------------------------------------------------------*)
  303.  
  304.  
  305. (*
  306.  . This procedure is called at the end of the timer ISR (interrupt service
  307.  . routine).  If you're using the optional DWT (DW Timer), this happens
  308.  . automagically.  If you wrote your own timer handler routine, you must
  309.  . call this function regularly.
  310. *)
  311. procedure dws_Update;
  312. (*---------------------------------------------------------------------------*)
  313.  
  314.  
  315. (*
  316.  . Each function in this section has a boolean return value.  A 0 (false)
  317.  . indicates that the function failed in some way.  In this case, call
  318.  . dws_ErrNo to get the specific error.  Otherwise, a return value of 1
  319.  . (true) indicates that all is well.
  320. *)
  321. function dws_DetectHardWare(dov : dws_DOPTR; dr : dws_DRPTR) : word;
  322.  
  323. function dws_Init(dr : dws_DRPTR; ideal : dws_IDPTR) : word;
  324.  
  325. (*
  326.  . If the program has called dws_Init, it _MUST_ call dws_Kill before it
  327.  . terminates.
  328.  .
  329.  . NB: Trap critical errors.  Don't let DOS put up the
  330.  .     "Abort, Retry, Fail?" text.  ('sides, it'll destroy your pretty gfx)
  331. *)
  332. function dws_Kill : word;
  333.  
  334.  
  335. (*
  336.  . The following 3 functions comprise the mixer section of the STK.  A
  337.  . value of 0 turns a channel off; a value of 255 is the loudest.
  338. *)
  339. function dws_XMaster(volume : word) : word;
  340.  
  341. function dws_XMusic(volume : word) : word;
  342.  
  343. function dws_XDig(volume : word) : word;
  344.  
  345.  
  346.  
  347. (*
  348.  . The following 10 functions comprise the digitized sound functions of
  349.  . the STK.  See the documentation for complete details.
  350. *)
  351. function dws_DPlay(dplay : dws_DPPTR) : word;
  352.  
  353. function dws_DSoundStatus(soundnum : word; result : dws_WDPTR) : word;
  354.  
  355. function dws_DSetRate(frequency : word) : word;
  356.  
  357. function dws_DGetRate(result : dws_WDPTR) : word;
  358.  
  359. (* This function is callable at any time*)
  360. function dws_DGetRateFromDWD(snd : dws_ADDRESS; result : dws_WDPTR) : word;
  361.  
  362. function dws_DDiscard(soundnum : word) : word;
  363.  
  364. function dws_DDiscardAO(snd : dws_ADDRESS) : word;
  365.  
  366. function dws_DClear : word;           (*All*)
  367.  
  368. function dws_DPause : word;           (*All*)
  369.  
  370. function dws_DUnPause : word;         (*All*)
  371.  
  372.  
  373. (*
  374.  . The following 5 functions comprise the music functions of the STK.
  375.  . See the documentation for complete details.
  376. *)
  377. function dws_MPlay(mplay : dws_MPPTR) : word;
  378.  
  379. function dws_MSongStatus(status : dws_WDPTR) : word;
  380.  
  381. function dws_MClear : word;
  382.  
  383. function dws_MPause : word;
  384.  
  385. function dws_MUnPause : word;
  386. (*---------------------------------------------------------------------------*)
  387.  
  388.  
  389. (*
  390.  . The following 5 functions/procedures comprise the timer functions of the STK.
  391.  . See the documentation for complete details.
  392. *)
  393.  
  394. (* See const declarations above for rates *)
  395. procedure dwt_Init(rate : word);
  396.  
  397. (*
  398.  . If the program has called dwt_Init, it _MUST_ call dwt_Kill before it
  399.  . terminates.
  400.  .
  401.  . NB: Trap critical errors.  Don't let DOS put up the
  402.  .     "Abort, Retry, Fail?" text.  ('sides, it'll destroy your pretty gfx)
  403. *)
  404. procedure dwt_Kill;
  405.  
  406. (* The following 2 procedures affect the timer, but not the music *)
  407. procedure dwt_Pause;
  408.  
  409. procedure dwt_UnPause;
  410.  
  411. (*
  412.  . Number of ticks since Beginning of World
  413. *)
  414. function dwt_MasterTick : longint;
  415. (*---------------------------------------------------------------------------*)
  416.  
  417. {$IFNDEF DPMI}
  418. (*
  419.  . The following function is for creating a real-mode wrapper (for use
  420.  . by protected-mode).  It's installed as an interrupt handler on a
  421.  . "user" interrupt vector.  See stkrun.pas.
  422. *)
  423. procedure dws_Wrap;
  424.  
  425. {$ENDIF}
  426.  
  427. (*****************************************************************************)
  428.  
  429.  
  430.  
  431. implementation
  432.  
  433. function dws_ErrNo : word; external;
  434.  
  435. procedure dws_Update; external;
  436.  
  437.  
  438. function dws_DetectHardWare(dov : dws_DOPTR; dr : dws_DRPTR) : word; external;
  439.  
  440. function dws_Init(dr : dws_DRPTR; ideal : dws_IDPTR) : word; external;
  441.  
  442. function dws_Kill : word; external;
  443.  
  444.  
  445. function dws_XMaster(volume : word) : word; external;
  446.  
  447. function dws_XMusic(volume : word) : word; external;
  448.  
  449. function dws_XDig(volume : word) : word; external;
  450.  
  451.  
  452. function dws_DPlay(dplay : dws_DPPTR) : word; external;
  453.  
  454. function dws_DSoundStatus(soundnum : word; result : dws_WDPTR) : word; external;
  455.  
  456. function dws_DSetRate(frequency : word) : word; external;
  457.  
  458. function dws_DGetRate(result : dws_WDPTR) : word; external;
  459.  
  460. function dws_DGetRateFromDWD(snd : dws_ADDRESS; result : dws_WDPTR) : word; external;
  461.  
  462. function dws_DDiscard(soundnum : word) : word; external;
  463.  
  464. function dws_DDiscardAO(snd : dws_ADDRESS) : word; external;
  465.  
  466. function dws_DClear : word; external;
  467.  
  468. function dws_DPause : word; external;
  469.  
  470. function dws_DUnPause : word; external;
  471.  
  472.  
  473. function dws_MSongStatus(status : dws_WDPTR) : word; external;
  474.  
  475. function dws_MPlay(mplay : dws_MPPTR) : word; external;
  476.  
  477. function dws_MClear : word; external;
  478.  
  479. function dws_MPause : word; external;
  480.  
  481. function dws_MUnPause     : word; external;
  482.  
  483.  
  484. procedure dwt_Init(rate : word); external;
  485.  
  486. procedure dwt_Kill; external;
  487.  
  488. procedure dwt_Pause; external;
  489.  
  490. procedure dwt_UnPause; external;
  491.  
  492. function dwt_MasterTick : longint; external;
  493.  
  494.  
  495. procedure dws_Wrap; external;
  496.  
  497.  
  498.  
  499. end.
  500.